View Modifiers are structures which allow you to apply the same style to multiple Views.
They are useful if you want multiple Views to look the same allowing you to define their style in one place only.
They take a View to which they are applied, and apply styles defined inside the View Modifier.
View Modifiers can also be used to modify other View Modifiers.
ContentView.swift
struct ContentView: View {
struct LabelStyle: ViewModifier {
func body(content: Content) -> some View {
return content
.foregroundColor(Color.red)
.shadow(color: Color.black, radius: 2, x: 2, y: 2)
.font(Font.custom("Arial Rounded MT Bold", size: 18))
}
}
var body: some View {
Text("Score").modifier(LabelStyle())
}
}
View